package com.tengju.bff.interfaces.shared;

import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: Dylan
 * @date: 2021/8/9 1:00 上午
 */
public class StringConvertUtil {

    /**
     * 将String转换成List<Long>并且去重
     */
    public static List<Long> stringConvertToLongList(String str){

        if (StringUtils.isBlank(str)){
            return Collections.emptyList();
        }

        List<String> list = List.of(StringUtils.trim(str).split(","));
        try {
            return list.stream().map(StringUtils::trim).map(Long::parseLong).distinct().collect(Collectors.toList());
        }catch (Exception e){
            throw new InterfaceException(InterfaceCode.STRING_NOT_CONVERT_TO_LONG_LIST);
        }
    }

}
